package com.platform.web.controller.module;

import com.platform.common.annotation.Log;
import com.platform.common.core.controller.BaseController;
import com.platform.common.core.domain.AjaxResult;
import com.platform.common.core.page.TableDataInfo;
import com.platform.common.enums.BusinessType;
import com.platform.common.utils.poi.ExcelUtil;
import com.platform.module.domain.MeterRead;
import com.platform.module.service.IMeterReadService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 热数据记录Controller
 *
 * @author wangqi
 * @date 2020-08-04
 */
@Controller
@RequestMapping("/module/calorimeter/read")
public class MeterReadController extends BaseController
{
    private String prefix = "module/calorimeter/read";

    @Autowired
    private IMeterReadService meterReadService;

    @RequiresPermissions("module:calorimeter:read:view")
    @GetMapping("/{calorimeterId}")
    public String read(@PathVariable("calorimeterId") String calorimeterId, ModelMap mmap)
    {
        if(calorimeterId.equals("0")){
            calorimeterId = "";
        }
        mmap.put("calorimeterId",calorimeterId);
        return prefix + "/read";
    }

    /**
     * 查询热数据记录列表
     */
    @RequiresPermissions("module:calorimeter:read:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MeterRead meterRead)
    {
        startPage();
        List<MeterRead> list = meterReadService.selectMeterReadList(meterRead);
        return getDataTable(list);
    }

    /**
     * 导出热数据记录列表
     */
    @RequiresPermissions("module:calorimeter:read:export")
    @Log(title = "热表数据记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MeterRead meterRead)
    {
        List<MeterRead> list = meterReadService.selectMeterReadList(meterRead);
        ExcelUtil<MeterRead> util = new ExcelUtil<MeterRead>(MeterRead.class);
        return util.exportExcel(list, "热表数据");
    }
}
